#!/usr/bin/env bash

set -eu

graph_w=72
graph_h=12

summary_lines=$((graph_h + 10))

if [ $# -lt 2 ]; then
    echo "Usage: $0 MASSIF_OUT_BEFORE MASSIF_OUT_AFTER DESC?" 1>&2
    exit 1
fi
massif_before="$1"
massif_after="$2"
shift 2

desc=
if [ $# -gt 0 ]; then
    desc="$1"
fi
shift 1

printf '## Performance Summary\n'
printf '\n'
if [ -n "$desc" ]; then
    printf '%s\n' "$desc"
    printf '\n'
fi
printf '<details>\n'
printf '<summary>Before</summary>\n'
printf '\n'
printf '```\n'
ms_print --x="$graph_w" --y="$graph_h" "$massif_before" | head -n +$summary_lines
printf '```\n'
printf '</details>\n'
printf '\n'
printf '<details>\n'
printf '<summary>After</summary>\n'
printf '\n'
printf '```\n'
ms_print --x="$graph_w" --y="$graph_h" "$massif_after" | head -n +$summary_lines
printf '```\n'
printf '</details>\n'
